Repository navigation
Report explicit tail calls as unsupported instead of panicking - #5152
feliperodri merged 2 commits into
Conversation
The diff checks internal MIR before body conversion during transformation, proof metadata generation, and autoharness processing, including instantiation search. It reports each explicit tail call in the body at its source span and aborts with an unsupported-feature diagnostic. It adds a diagnostic regression test and a verification case where the harness never calls the function containing `become`. It also documents explicit tail calls as unsupported. Fixes model-checking#5131
There was a problem hiding this comment.
🟡 Changes recommended
Stub validation can still panic on become because body conversions occur before the guard, leaving earlier conversions and body loaders unprotected for both concrete and generic stubs.
1 open issue
What changed in this PR
This PR addresses #5131 by checking for explicit tail calls (become) before MIR conversion, so Kani can report an unsupported-feature diagnostic instead of a compiler panic.
Changes:
- Adds checks during transformation, proof metadata generation, and autoharness processing.
- Adds diagnostic and unreachable-function regression cases.
- Documents explicit tail calls as unsupported.
| File | Description |
|---|---|
tests/ui/explicit-tail-calls/main.rs |
Adds a reachable tail-call diagnostic case. |
tests/ui/explicit-tail-calls/expected |
Specifies the expected unsupported-feature error. |
tests/kani/TailCall/unreachable.rs |
Checks that an uncalled tail-call function does not affect verification. |
kani-compiler/src/kani_middle/transform/mod.rs |
Checks for tail calls before transforming bodies. |
kani-compiler/src/kani_middle/mod.rs |
Adds the shared internal-MIR check and diagnostic. |
kani-compiler/src/kani_middle/metadata.rs |
Checks harness bodies before metadata conversion. |
kani-compiler/src/kani_middle/codegen_units.rs |
Adds checks to autoharness processing and instantiation search. |
docs/src/rust-feature-support/unstable.md |
Lists explicit tail calls as unsupported. |
Review effort: Balanced
feliperodri
left a comment
There was a problem hiding this comment.
Thanks, reporting become instead of panicking inside rustc_public is the right fix, and checking the internal MIR before conversion targets the actual failure. The two tests cover the reachable and unreachable cases. A few things before merge:
- Remaining panics. Several places still convert bodies before any guard. One is stub validation (
stubbing/mod.rs:81-82, Copilot's thread), which I agree with. Others: the stub body inFnStubPass(transform/stubs.rs:148), and mined invariants under--constructor-args/--check-invariants(mined_invariants.rs:320and:440, which load every inherent method of a type). Rather than "call this right beforeinstance.body()", which is easy to miss in the next new caller, consider one helper such aschecked_body(tcx, instance) -> Option<Body>that does both, and use it at every call site. Please add a stubbing regression as Copilot suggests. - Autoharness aborts the whole run.
automatic_harness_partitioncalls the check for every local function, so a singlebecomeanywhere in the crate stops autoharness, and no other function gets a verdict. #5119 fixed the same problem for uninhabited downcasts. Could such functions be skipped instead, with a reason like "explicit tail calls are not supported", as other ineligible functions are? Please add an autoharness test for it. - PR description. The Testing section reads like a tool transcript ("the kani resolve_deferred_fn_slots change", "the transcript does not record its exit status"). Please say what you ran and what passed. CI covers the rest.
I added [F] Crash and [E] Unsupported Construct (from #5131).
…utoharness Address review on model-checking#5152: rather than calling a guard before each `instance.body()`, add helpers in `kani_middle` that check the internal MIR for `TerminatorKind::TailCall` and then convert: - `checked_body` / `checked_fn_def_body` report the unsupported diagnostic and abort. Used by `body_ref`, harness metadata, stub validation (`check_compatibility`), the stub body in `FnStubPass`, the autoharness transform, delayed-UB / points-to analysis and mutual-recursion checks. - `has_explicit_tail_call` / `body_without_tail_calls` report nothing. Used where an unsupported body should just be ignored: autoharness eligibility, instantiation search, constructor inlining, invariant mining (`--constructor-args` / `--check-invariants`) and the diagnostic-only `kani::any` cycle check. `ExternFnStubPass` now asks `FnDef::has_body` instead of converting the body just to test for one. Autoharness no longer aborts the run when one function uses `become`: it is skipped with the new `AutoHarnessSkipReason::UnsupportedTailCall` ("Explicit tail calls are not supported"), and the other functions are still verified. Tests: stubbing regressions with `become` in the original and in the replacement (both panicked in `rustc_public` before), and an autoharness run where `tail_call` is skipped and `ok_fn` is verified (the whole run aborted before).
|
Thanks for the thorough review. Addressed in fa462b8:
|
feliperodri
left a comment
There was a problem hiding this comment.
Thanks @mvanhorn, this round addresses everything from my last review. checked_body / checked_fn_def_body, with body_without_tail_calls for the heuristics, is a good split. Stub validation, FnStubPass, mined invariants and autoharness now all go through it, and the stubbing and autoharness tests cover the new paths.
I built fa462b8 and ran the new ui, kani and script-based-pre tests, plus the expected/kani stubbing suites; all pass.
One case is still open, and I'll track it in a follow-up issue rather than block this PR. Autoharness skips a function that contains become, but not one that calls such a function. With pub fn caller(x: u8) -> u8 { tail_call(x % 3) } in the same crate, the run aborts at the diagnostic and ok_fn gets no verdict. That's a proper error now, not the panic from #5131, but ideally only the harnesses that reach the become would fail. The experimental LLBC backend (mir_to_ullbc) also still loads bodies with instance.body() directly.
Optional: my earlier nit on internal_body_kind still applies. It's an identity mapping apart from Intrinsic → Item, so match … { InstanceKind::Intrinsic(d) => InstanceKind::Item(d), def => def } says that directly.
The red macos-14 jobs are a runner configuration issue, unrelated to this PR.
|
Follow-up for the remaining cases: #5160. |
7f89576
|
Thanks for merging this, @feliperodri. Explicit tail calls ( |

Why
Verifying code that uses an explicit tail call (
become) can crash the compiler with a “not implemented” panic instead of reporting an unsupported feature.rustc_publichas noTailCallterminator variant, so converting a body containing one reachesunimplemented!(). Kani loaded these bodies without checking for explicit tail calls first.What changed
The diff checks internal MIR before body conversion during transformation, proof metadata generation, and autoharness processing, including instantiation search. It reports each explicit tail call in the body at its source span and aborts with an unsupported-feature diagnostic. It adds a diagnostic regression test and a verification case where the harness never calls the function containing
become. It also documents explicit tail calls as unsupported.Testing
Run locally on macOS with the pinned toolchain (
nightly-2026-10-23):cargo build-dev,cargo fmt --checkandcargo clippy -p kani-compiler -p kani-driver -p kani_metadata --all-targets -- -D warningspass.cargo run -p compiletest -- --suite ui --mode expected explicit-tail-calls: 3 passed (ui/explicit-tail-calls/main.rsand the two new stubbing tests).cargo run -p compiletest -- --suite kani --mode kani TailCall: 1 passed.cargo run -p compiletest -- --suite script-based-pre --mode exec autoharness: 47 passed, including the newautoharness_explicit_tail_call, wheretail_callis skipped andok_fnis verified.cargo run -p compiletest -- --suite expected --mode expected stub contract: 230 passed.rustc_publicand the autoharness run aborts.Fixes #5131
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
AI was used for assistance.